/*
 *   Copyright (C) 2010  Jens Kieselbach
 * 
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 * 
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 * 
 *   You may obtain a copy of the License at http://www.gnu.org/licenses/gpl.html
 */

package de.kieselbach.swing

import java.awt.BasicStroke
import java.awt.Color
import java.awt.Component
import java.awt.Graphics
import java.awt.Graphics2D
import java.awt.RenderingHints

import javax.swing.Icon


class SplitButtonArrowIcon implements Icon {

    int size
    int middle
    Color color = Color.black

    public SplitButtonArrowIcon(int s) {

        if (s < 3) {
            throw new IllegalArgumentException()
        }

        if (s % 2 != 0) {
            s++
        }
        size = s
        middle = (size - 2) / 2
    }

    public int getIconHeight() {

        return size
    }

    public int getIconWidth() {

        return size
    }

    public void paintIcon(Component c, Graphics g, int x, int y) {

        Graphics2D g2d = (Graphics2D)g
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
        g2d.setStroke(new BasicStroke(1.0f))
        g2d.setColor(color)

        g2d.drawLine(x, y + 1, x + middle, y + 1 + middle)
        g2d.drawLine(x + size - 2, y + 1, x + middle, y + 1 + middle)
    }
}
